#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 55;
char s[10][10];
int main()
{
	int t;
	cin >> t;
	while (t--) {
		bool flag = 0;
		int idx1 = 0, idx2 = 0;
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				cin >> s[i][j];
				if (s[i][j] != '.' && !flag) {
					flag = 1;
					idx1 = i;
					idx2 = j;
				}
			}
		}
		string ans;
		for (int i = idx1; i < 8; i++) {
			if (s[i][idx2] != '.') {
				ans += s[i][idx2];
			}
		}
		cout << ans << endl;
	}
	return 0;
}